//API进行统一管理
import { method } from "lodash"
import requests from "./ajax"
import mockRequest from "./mockAjax"

// 三级联动接口
// /api/product/getBaseCategoryList  get  无参数
export const reqCategoryList = () => {
    // 发请求（不需要加api，baseURL默认加上了）,返回结果是Promise对象
    return requests({url:'/product/getBaseCategoryList',method:'get'})
}

// 获取banner（Home首页轮播图接口）
export const reqGetBannerList = () => {
    return mockRequest.get('/banner')
}

// 获取floor的数据（Home首页floor接口）
export const reqGetFloorList = () => {
    return mockRequest.get('/floor')
}

// 获取搜索模块的数据   地址：/api/list   类型：post
// 需要带参数如：
/*{
    "category3Id": "61",
    "categoryName": "手机",
    "keyword": "小米",
    "order": "1:desc",
    "pageNo": 1,
    "pageSize": 10,
    "props": ["1:1700-2799:价格", "2:6.65-6.74英寸:屏幕尺寸"],
    "trademark": "4:小米"
  }*/
//   当前这个接口，给服务器传递参数至少是一个空对象
export const reqGetSearchList = (params) => {
      return requests({url:"/list", method:"post",data:params})
}
  
// 获取商品详情的接口 请求方式：get   请求地址：/api/item/{ skuId }
export const reqGoodsInfo = (skuId) => {
    return requests({url:`/item/${skuId}`, method:"get"})
}

// 将产品添加到购物车的接口（获取更行某一个产品的个数）
// /api/cart/addToCart/{ skuId }/{ skuNum }    POST
export const reqAddOrUpdateShopCart = (skuId, skuNum) => {
    return requests({url:`/cart/addToCart/${skuId}/${skuNum}`,method:"post"})
}

// 获取购物车列表的接口  /api/cart/cartList   get
export const reqCartList = () => {
    return requests({url:`/cart/cartList`,method:"get"})
}

// 删除购物车产品的接口  /api/cart/deleteCart/{skuId}   delete
export const reqDeleteCartById = (skuId) => {
    return requests({url:`/cart/deleteCart/${skuId}`,method:"delete"})
}

// 修改产品的选中状态接口   /api/cart/checkCart/{skuID}/{isChecked}    get
export const reqUpdateCheckedById = (skuId, isChecked) => {
    return requests({url:`/cart/checkCart/${skuId}/${isChecked}`, method:"get"})
}

// 获取验证码接口  /api/user/passport/sendCode/{phone}  get
export const reqGetCode = (phone) => {
    return requests({url:`/user/passport/sendCode/${phone}`, method:"get"})
}

// 注册接口 /api/user/passport/register   post
export const reqUserRegister = (data) => {
    return requests({url:`/user/passport/register`, data, method:"post"})
}

// 登录接口  /api/user/passport/login  post
export const reqUserLogin = (data) => {
    return requests({url:`/user/passport/login`,data,method:"post"})
}

//获取用户的信息接口【需要带着用户的token向服务器要用户信息】  /api/user/passport/auth/getUserInfo  method:get
export const reqUserInfo = () => {
    return requests({url:'/user/passport/auth/getUserInfo', method:'get'})
}

// 退出登录的接口   /api/user/passport/logout   get
export const reqUserOut = () => {
    return requests({url:'/user/passport/logout',method:'get'})
}

//获取用户地址信息  /api/user/userAddress/auth/findUserAddressList   get
export const reqAddressInfo = () => {
    return requests({url:'/user/userAddress/auth/findUserAddressList',method:'get'})
}

// 获取用户商品清单  /api/order/auth/trade  get
export const reqOrderInfo = () => {
    return requests({url:'/order/auth/trade', method:'get'})
}

// 提交订单   /api/order/auth/submitOrder?tradeNo={tradeNo}   post   参数：tradeNo,6个商品信息
export const reqSubmitOrder = (tradeNo, data) => {
    return requests({url:`/order/auth/submitOrder?tradeNo=${tradeNo}`,data,method:'post'})
}

// 获取支付信息   /api/payment/weixin/createNative/{orderId}   get   参数：orderId
export const reqPayInfo = (orderId) => {
    return requests({url:`/payment/weixin/createNative/${orderId}`,method:'get'})
}

//获取订单支付状态   /api/payment/weixin/queryPayStatus/{orderId}   get  参数：orderId
export const reqPayStatus = (orderId) => {
    return requests({ url: `/payment/weixin/queryPayStatus/${orderId}`, method: 'get' })
}

// 获取我的订单列表  /api/order/auth/{page}/{limit}   get   参数:page(页码),limit(每页的数量)
export const reqMyOrderList = (page, limit) => {
    return requests({url:`/order/auth/${page}/${limit}`,method:'get'}) 
}